package com.dwork.base.controller;

import java.io.UnsupportedEncodingException;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

@Controller
@RequestMapping(value="error")
public class ErrorController extends BaseController{
	/**
	 * 指向拒绝访问页面
	 * @return
	 */
	public ModelAndView getRefuseMV(String message) {
		ModelAndView mv = getBaseMV("/refuse");
		mv.addObject("message", message);
		return mv;
	}
	@RequestMapping(value="/400")
	public ModelAndView get400(@ModelAttribute("message") String message,@ModelAttribute("status") String status) {
		
		ModelAndView mv = getBaseMV("/400");
		try {
//			String message1 = new String(message.getBytes("UTF-8"),"ISO-8859-1");
			message = new String(message.getBytes("ISO-8859-1"),"UTF-8");
//			String message5 = new String(message.getBytes("GBK"),"ISO-8859-1");
//			String message6 = new String(message.getBytes("ISO-8859-1"),"GBK");
//			String message3 = new String(message.getBytes("GBK"),"UTF-8");
//			String message4 = new String(message.getBytes("UTF-8"),"GBK");
			//System.out.println("---------1["+message1+"]---------2["+message2+"]---------3["+message3+"]---------4["+message1+"]---------5["+message5+"]---------6["+message6+"]---------");
			status = new String(status.getBytes("ISO-8859-1"),"UTF-8");
		} catch (UnsupportedEncodingException e) {
			
			e.printStackTrace();
		}
		
		mv.addObject(BaseController.MESSAGE, message);
		mv.addObject(BaseController.STATUS,status);
		return mv;
	}
	@RequestMapping(value="/500")
	public ModelAndView get500(@ModelAttribute("message") String message,@ModelAttribute("status") String status) {
		ModelAndView mv = getBaseMV("/500");
		try {
			message = new String(message.getBytes("ISO-8859-1"),"UTF-8");
			status = new String(status.getBytes("ISO-8859-1"),"UTF-8");
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		}
		mv.addObject(BaseController.MESSAGE, message);
		mv.addObject(BaseController.STATUS,status);
		return mv;
	}

}
